home *** CD-ROM | disk | FTP | other *** search
/ 500 MB Nyheder Direkte fra Internet 2 / 500 MB nyheder direkte fra internet CD 2.iso / start / data / text / pretty.txt < prev    next >
Text File  |  1994-09-21  |  32KB  |  786 lines

  1.  
  2.                       ZONES
  3.   The leftmost part of the screen is called the first zone. To 
  4. the right of that zone lies the second zone.
  5.   If your computer's fancy, it also has a third, fourth, and 
  6. fifth zone; and each zone 16 characters wide, so the entire 
  7. screen is 80 characters wide.
  8.   (If your computer's not so fancy, it might have fewer zones, or 
  9. the zones might be narrower; and the screen might be less than 80 
  10. characters wide. To find out about your computer's peculiarities, 
  11. read the ``Versions of BASIC'' appendix.)
  12.   A comma makes the computer jump to a new zone. Here's an 
  13. example:
  14. PRINT "SIN","KING"
  15. The computer will print SIN and KING on the same line; but 
  16. because of the comma before KING, the computer will print KING in 
  17. the second zone, like this:
  18. SIN             KING
  19.  
  20.    first zone      second zone     third zone      fourth zone     
  21. fifth zone
  22.   To turn that example into a program, put a number in front of 
  23. the line, like this:
  24. 10 PRINT "SIN","KING"
  25. When you type RUN, the computer will print:
  26. SIN             KING
  27.   This program does the same thing:
  28. 10 PRINT "SIN",
  29. 20 PRINT "KING"
  30. Line 10 makes the computer print SIN and then jump to the next 
  31. zone. Line 20 makes the computer print KING. The computer will 
  32. print:
  33. SIN             KING
  34.   This example's silly:
  35. PRINT "LOVE","CRIES","OUT"
  36. The computer will print LOVE in the first zone, CRIES in the 
  37. second zone, and OUT in the third zone, like this:
  38. LOVE            CRIES           OUT
  39.   This example's even sillier:
  40. PRINT "LOVE","CRIES","OUT","TO","ME","AT","NIGHT"
  41. The computer will print LOVE in the first zone, CRIES in the 
  42. second, OUT in the third, TO in the fourth, ME in the fifth, and 
  43. the remaining words below, like this:
  44. LOVE            CRIES           OUT             TO              
  45. ME
  46. AT              NIGHT
  47.   This example tells a bad joke:
  48. PRINT "I THINK YOU ARE UGLY","I'M JOKING"
  49. The computer will print I THINK YOU ARE UGLY, then jump to a new 
  50. zone, then print I'M JOKING, like this:
  51. I THINK YOU ARE UGLY            I'M JOKING
  52.  
  53.    first zone      second zone     third zone      fourth zone     
  54. fifth zone
  55.   When you combine commas with semicolons, you can get weird 
  56. results:
  57. PRINT "EAT","ME";"AT";"BALLS","NO";"W"
  58. That line contains commas and semicolons. A comma makes the 
  59. computer jump to a new zone, but a semicolon does not make the 
  60. computer jump. The computer will print EAT, then jump to a new 
  61. zone, then print ME and AT and BALLS, then jump to a new zone, 
  62. then print NO and W. Altogether, the computer will print:
  63. EAT             MEATBALLS       NOW
  64.  
  65.                  Skipping a zone
  66.   You can make the computer skip over a zone:
  67. PRINT "JOE"," ","LOVES SUE"
  68. The computer will print JOE in the first zone, a blank space in 
  69. the second zone, and LOVES SUE in the third zone, like this:
  70. JOE                             LOVES SUE
  71.  
  72.    first zone      second zone     third zone      fourth zone     
  73. fifth zone
  74. You can type that example even more briefly, like this:
  75. PRINT "JOE",,"LOVES SUE"
  76.  
  77.                       Loops
  78.   This program makes the computer greet you:
  79. 10 PRINT "HI",
  80. 20 GO TO 10
  81.   The computer will print HI many times. Each time will be in a 
  82. new zone, like this:
  83. HI              HI              HI              HI              
  84. HI
  85. HI              HI              HI              HI              
  86. HI
  87. HI              HI              HI              HI              
  88. HI
  89. etc.
  90.  
  91.                      Tables
  92.   This program prints a list of words and their opposites:
  93. 10 PRINT "GOOD","BAD"
  94. 20 PRINT "BLACK","WHITE"
  95. 30 PRINT "GRANDPARENT","GRANDCHILD"
  96. 40 PRINT "HE","SHE"
  97.   Line 10 makes the computer print GOOD, then jump to the next 
  98. zone, then print BAD. Altogether, the computer will print:
  99. GOOD            BAD
  100. BLACK           WHITE
  101. GRANDPARENT     GRANDCHILD
  102. HE              SHE
  103.   The first zone contains a column of words; the second zone 
  104. contains the opposites. Altogether, the computer's printing looks 
  105. like a table. So whenever you want to make a table, use zones, by 
  106. putting commas in your program.
  107.   Let's make the computer print this table:
  108. NUMBER          SQUARE
  109.  3               9
  110.  4               16
  111.  5               25
  112.  6               36
  113.  7               49
  114.  8               64
  115.  9               81
  116.  10              100
  117. Here's the program:
  118. 10 PRINT "NUMBER","SQUARE"
  119. 20 FOR I = 3 TO 10
  120. 30     PRINT I,I*I
  121. 40 NEXT
  122. Line 10 prints the word NUMBER at the top of the first column, 
  123. and the word SQUARE at the top of the second. Line 20 says I goes 
  124. from 3 to 10; to begin, I is 3. Line 30 makes the computer print:
  125.  3               9
  126. Line 40 makes the computer do the same thing for the next I, and 
  127. for the next I, and for the next; so the computer prints the 
  128. whole table.
  129.  
  130.  
  131.            TAB
  132.   When the computer puts a line of information on your screen, 
  133. the leftmost character in the line is said to be at position 1.  
  134. The second character in the line is said to be at position 2.
  135.   This command makes the computer skip to position 6 and then 
  136. print ``HOT'':
  137. PRINT TAB(6)"HOT"
  138. The computer will print:
  139.      HOT
  140. 12345678
  141.   Here's a fancier example:
  142. PRINT TAB(6)"HOT";TAB(13)"BUNS"
  143. The computer will skip to the 6th position, then print ``HOT'', 
  144. then skip to the 13th position, then print ``BUNS'':
  145.      HOT    BUNS
  146. 12345678    13
  147.  
  148.         Diagonal
  149.   This program prints a diagonal line:
  150. 10 FOR I = 1 TO 12
  151. 20     PRINT TAB(I)"*"
  152. 30 NEXT
  153.   Line 10 says to do the loop twelve times, so the computer does 
  154. line 20 repeatedly. The first time the computer does line 20, the 
  155. I is 1, so the computer prints an asterisk at position 1:
  156. *
  157. The next time, the I is 2, so the computer skips to position 2 
  158. and prints an asterisk:
  159.  *
  160. The next time, the I is 3, so the computer skips to position 3 
  161. and prints an asterisk:
  162.   *
  163. Altogether, the program makes the computer print this picture:
  164. *
  165.  *
  166.   *
  167.    *
  168.     *
  169.      *
  170.       *
  171.        *
  172.         *
  173.          *
  174.           *
  175.            *
  176.  
  177.                                                Calendar
  178.                              Let's make the computer print a 
  179. calendar for the whole year. We must begin by telling the 
  180. computer how many days are in each month:
  181. Month's name                         Month's length
  182. January                              31
  183. February                             28 or 29
  184. March                                31
  185. April                                30
  186. May                                  31
  187. June                                 30
  188. July                                 31
  189. August                               31
  190. September                            30
  191. October                              31
  192. November                             30
  193. December                             31
  194. That list becomes our data:
  195. 10 DATA JANUARY,31,FEBRUARY,28,MARCH,31,APRIL,30
  196. 20 DATA MAY,31,JUNE,30,JULY,31,AUGUST,31
  197. 30 DATA SEPTEMBER,30,OCTOBER,31,NOVEMBER,30,DECEMBER,31
  198. (For a leap year, change line 10.)
  199.                              To make the computer look at that 
  200. data, tell the computer to READ:
  201. 40 READ N$,L
  202. That makes the computer read a month's Name and Length.
  203.                              To read all the data, the computer 
  204. should do line 40 twelve times. So put line 40 inside a loop, 
  205. like this:
  206. English                                  BASIC
  207. Here are the months                      10 DATA 
  208. JANUARY,31,FEBRUARY,28,MARCH,31,APRIL,30
  209. and their lengths.                       20 DATA 
  210. MAY,31,JUNE,30,JULY,31,AUGUST,31
  211.                                          30 DATA 
  212. SEPTEMBER,30,OCTOBER,31,NOVEMBER,30,DECEMBER,31
  213.  
  214. For each month,                          39 FOR M = 1 TO 12
  215.  
  216. read its Name & Length,                  40     READ N$,L
  217.  
  218. print its Name,                          50     PRINT N$
  219.  
  220. print all its days,                      60     FOR D = 1 TO L
  221.                                          70         PRINT D;
  222.                                          80     NEXT
  223.  
  224. and press the ENTER key                  90     PRINT
  225. twice at end of the month.               91     PRINT
  226.                                          100 NEXT
  227.                              When you run that program, the 
  228. computer prints a calendar beginning like this:
  229. JANUARY
  230.  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  
  231. 19  20
  232.  21  22  23  24  25  26  27  28  29  30  31
  233.  
  234. FEBRUARY
  235.  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  
  236. 19  20
  237.  21  22  23  24  25  26  27  28
  238.  
  239. MARCH
  240.  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  
  241. 19  20
  242.  21  22  23  24  25  26  27  28  29  30  31
  243.                              Pretty weeks Although that program 
  244. makes the computer print the right numbers for each month, it 
  245. prints the numbers in the wrong places. Let's make the computer 
  246. print at most 7 numbers in each row, so each is a week.
  247.                              To print the numbers in the right 
  248. places, use TAB:
  249. 70         PRINT TAB(T)D;
  250. Line 70 will make the computer print each day in the right 
  251. position . . . if we define T correctly. But how should we define 
  252. T?
  253.                              For Sunday, let's make T be 2, so 
  254. that Sunday begins at position 2. For Monday, let's make T be 6, 
  255. so that Monday begins at position 6. For Tuesday, let's make T be 
  256. 10; for Wednesday, 14; Thursday, 18; Friday, 22; and Saturday, 
  257. 26. So whenever a day's been printed, T should normally increase 
  258. by 4 for the next day:
  259. 71         T=T+4
  260.  
  261.   Saturday's the last day of the week; after Saturday, we must 
  262. begin a new week. So if T has passed Saturday (which is 26), we 
  263. want T to become 2 (for Sunday); and if there are more days left 
  264. in the month, we want the computer to press the ENTER key (to 
  265. start a new week):
  266. 72         IF T>26 THEN T=2: IF D<L THEN PRINT
  267.   Which year would you like a calendar for: 1993? 1994? 1995? 
  268. This program makes a pretty calendar for 1993:
  269. 1 PRINT "CALENDAR FOR 1993"
  270. 2 PRINT                    
  271. 3 T=22                     
  272. 10 DATA JANUARY,31,FEBRUARY,28,MARCH,31,APRIL,30
  273. 20 DATA MAY,31,JUNE,30,JULY,31,AUGUST,31
  274. 30 DATA SEPTEMBER,30,OCTOBER,31,NOVEMBER,30,DECEMBER,31
  275. 39 FOR M = 1 TO 12
  276. 40     READ N$,L
  277. 50     PRINT N$
  278. 51     PRINT "  SUN MON TUE WED THU FRI SAT"
  279. 60     FOR D = 1 TO L
  280. 70         PRINT TAB(T)D;
  281. 71         T=T+4
  282. 72         IF T>26 THEN T=2: IF D<L THEN PRINT
  283. 80     NEXT
  284. 90     PRINT
  285. 91     PRINT
  286. 100 NEXT
  287.   Line 1 prints the heading. Line 2 puts a blank line underneath 
  288. the heading. Since 1993 begins on a Friday, line 3 tells the 
  289. computer to start T at 22 (which is the position for Friday). 
  290. Line 51 prints the heading for each month; when you type that 
  291. line, put 2 blank spaces before SUN.
  292.   The computer will print a calendar beginning like this:
  293. CALENDAR FOR 1993
  294.  
  295. JANUARY
  296.   SUN MON TUE WED THU FRI SAT
  297.                       1   2
  298.   3   4   5   6   7   8   9
  299.   10  11  12  13  14  15  16
  300.   17  18  19  20  21  22  23
  301.   24  25  26  27  28  29  30
  302.   31
  303.  
  304. FEBRUARY
  305.   SUN MON TUE WED THU FRI SAT
  306.       1   2   3   4   5   6
  307.   7   8   9   10  11  12  13
  308.   14  15  16  17  18  19  20
  309.   21  22  23  24  25  26  27
  310.   28
  311.  
  312. MARCH
  313.   SUN MON TUE WED THU FRI SAT
  314.       1   2   3   4   5   6
  315.   7   8   9   10  11  12  13
  316.   14  15  16  17  18  19  20
  317.   21  22  23  24  25  26  27
  318.   28  29  30  31
  319.   Variations If you want a different year, change lines 1 and 3. 
  320. For a leap year, change line 10.
  321.   If you want the calendar to be taller, insert extra blank 
  322. lines. To do that, replace ``PRINT'' by ``PRINT: PRINT: PRINT'' 
  323. in lines 2, 72, 90, and 91:
  324. 2 PRINT: PRINT: PRINT
  325. 72         IF T>26 THEN T=2: IF D<L THEN PRINT: PRINT: PRINT
  326. 90     PRINT: PRINT: PRINT
  327. 91     PRINT: PRINT: PRINT
  328.   If you want the calendar to look wider (or narrower), change 
  329. the positions for Sunday, Monday, Tuesday, etc, by changing the T 
  330. numbers (in lines 3, 51, 71, and 72).
  331.  
  332.                LOCATE
  333.                                          The computer makes the 
  334. screen show several lines of information. On the screen, the top 
  335. line is called line 1; underneath it is line 2; then comes line 
  336. 3; etc.
  337.                                          Each line consists of 
  338. many characters. The leftmost character is at position 1; the 
  339. next character is at position 2; etc.
  340.                                          On the screen, the 
  341. computer will print wherever you wish.
  342.                                          For example, to make the 
  343. computer print the word DROWN so that DROWN begins at line 3's 
  344. 7th position, type this:
  345. LOCATE 3,7: PRINT "DROWN"
  346. The computer will print the word's first letter (D) at line 3's 
  347. 7th position. The computer will print the rest of the word 
  348. afterwards.
  349.                                          You'll see the first 
  350. letter (D) at line 3's 7th position, the next letter (R) at the 
  351. next position (line 3's 8th position), the next letter (O) at the 
  352. next position (line 3's 9th position), etc.
  353.  
  354.                                                    Your computer
  355.                                          Most computers 
  356. understand the word LOCATE, but your computer might be different. 
  357. To find out about your computer, check the ``Versions of BASIC'' 
  358. appendix.
  359.  
  360.                PIXELS
  361.   The image on the computer's screen is called the picture. If 
  362. you stare at the picture closely, you'll see the picture's 
  363. composed of thousands of tiny rectangles. Each tiny rectangle is 
  364. called a picture's element, or pic's el, or pixel, or pel.
  365.  
  366.              Coordinates
  367.   The tiny rectangle in the screen's upper-left corner is called 
  368. pixel (0,0); just to the right of it is pixel (1,0); then comes 
  369. pixel (2,0); etc. Underneath pixel (0,0) is pixel (0,1). Here are 
  370. the positions of the pixels:
  371. pixel (0,0)   pixel (1,0)   pixel (2,0)   pixel (3,0)   pixel 
  372. (4,0)   etc.
  373. pixel (0,1)   pixel (1,1)   pixel (2,1)   pixel (3,1)   pixel 
  374. (4,1)   etc.
  375. pixel (0,2)   pixel (1,2)   pixel (2,2)   pixel (3,2)   pixel 
  376. (4,2)   etc.
  377. pixel (0,3)   pixel (1,3)   pixel (2,3)   pixel (3,3)   pixel 
  378. (4,3)   etc.
  379.   Each pixel's name consists of two numbers in parentheses. The 
  380. first number's called the X coordinate; the second number's 
  381. called the Y coordinate. For example, if you're talking about 
  382. pixel (4,3) its X coordinate is 4, and its Y coordinate is 3.
  383.   The X coordinate tells how far to the right the pixel is. The Y 
  384. coordinate tells how far down. So pixel (4,3) is the pixel that's 
  385. 4 to the right and 3 down.
  386.   On the computer, the Y coordinate measures how far down, not 
  387. up! If you've had the misfortune of reading old-fashioned math 
  388. books in which the Y coordinate measured how far up, you'll have 
  389. to reverse your thinking!
  390.  
  391.           How many pixels?
  392.   How many pixels are on the screen? The answer depends on which 
  393. computer you have.
  394.   If your computer's typical, the X coordinate goes from 0 to 
  395. 319, and the Y coordinate goes from 0 to 199. So on a typical 
  396. computer, the pixel at the screen's lower right-hand corner is 
  397. pixel (319,199); and the total number of pixels on the screen is 
  398. ``320 times 200'' which is 64 thousand.
  399.   But your computer might not be ``typical''. Check the 
  400. ``Versions of BASIC'' appendix.
  401.  
  402.          Fundamental shapes
  403.   The computer can draw three fundamental shapes: dots, lines, 
  404. and circles.
  405.   To make the computer draw a dot at pixel (100,100), say:
  406. PLOT (100,100)
  407.   Though some computers understand the word PLOT, other computers 
  408. require a different word instead, such as ``DRAW'' or ``PSET''. 
  409. To find out which word your computer understands, check the 
  410. ``Versions of BASIC'' appendix. For example, the appendix says 
  411. that if you have an IBM PC or clone, you must say ``PSET'' 
  412. instead of ``PLOT''. The appendix also says that if you have an 
  413. IBM PC or clone, you must give a command such as ``SCREEN 1'' 
  414. before giving any graphics commands, so begin like this:
  415. SCREEN 1
  416. PSET (100,100)
  417.  
  418.                                          To make the computer 
  419. draw a line from pixel (0,0) to pixel (100,100), say:
  420. LINE (0,0)-(100,100)
  421.                                          To make the computer 
  422. draw a line from pixel (0,0) to pixel (100,100), and then draw a 
  423. line from that pixel (100,100) to pixel (70,120), say:
  424. LINE (0,0)-(100,100)
  425. LINE -(70,120)
  426.                                          To make the computer 
  427. draw a circle whose center is pixel (100,100) and whose radius is 
  428. 50, say:
  429. CIRCLE (100,100),50
  430.                                          The computer draws each 
  431. shape in white, on a black background.
  432.  
  433.                                                        PAINT
  434.                                          After you've drawn an 
  435. outline of a shape (by using dots, lines, and circles), you can 
  436. fill in the middle of the shape, by telling the computer to PAINT 
  437. the shape.
  438.                                          Here's how to PAINT a 
  439. shape that you've drawn (such as a circle or a house). Find a 
  440. pixel that's in the middle of the shape and that's still black; 
  441. then tell the computer to PAINT, starting at that pixel. For 
  442. example, if pixel (100,101) is inside the shape and is still 
  443. black, say:
  444. PAINT (100,101)
  445.  
  446.                                                       Colors
  447.                                          You can use these 
  448. colors:
  449. 0. black                                              8. light 
  450. black (gray)
  451. 1. blue                                               9. light 
  452. blue
  453. 2. green                                             10. light 
  454. green
  455. 3. cyan (greenish blue)                              11. light 
  456. cyan (aqua)
  457. 4. red                                               12. light 
  458. red (pink)
  459. 5. magenta (purplish red)                            13. light 
  460. magenta
  461. 6. brown                                             14. light 
  462. brown (yellow)
  463. 7. cream (yellowish white)                           15. light 
  464. cream (pure white)
  465.                                          Normally, the PLOT, 
  466. LINE, CIRCLE, and PAINT commands draw in yellowish white (cream). 
  467. If you prefer a different color, put a comma and the color's 
  468. number at the end of the command. For example, if you want to 
  469. draw a line from (0,0) to (100,0) in green (whose color number is 
  470. 2), type this:
  471. LINE (0,0)-(100,0),2
  472.                                          When you give a PAINT 
  473. command, you must make its color the same as the color of the 
  474. outline you're filling in.
  475.                                          If your screen is a TV 
  476. or composite monitor (instead of an RGB monitor) or your computer 
  477. is obsolescent (such as an Apple 2), you'll get the correct 
  478. colors only when you draw horizontal lines and adjust the COLOR 
  479. and TINT dials. When you draw vertical lines or diagonals or 
  480. circles or dots, the colors will be slightly off.
  481.           Boxes
  482.   If you type ___ 
  483. LINE (0,0)-(100,100),2
  484. the computer draws a line from pixel (0,0) to (100,100) using 
  485. color 2.
  486.   If you put the letter B at the end of the LINE command, like 
  487. this ___ 
  488. LINE (0,0)-(100,100),2,B
  489. the computer will draw a box instead of a line. One corner of the 
  490. box will be at pixel (0,0); the opposite corner will be at 
  491. (100,100); and the box will be drawn using color 2.
  492.   If you put BF at the end of the LINE command, like this ___ 
  493. LINE (0,0)-(100,100),2,BF
  494. the computer will draw a box and also fill it in, by painting its 
  495. interior.
  496.  
  497.                      SOUNDS
  498.                              To produce sounds, you can say BEEP, 
  499. SOUND, or PLAY. BEEP appeals to business executives; SOUND 
  500. appeals to doctors and engineers; and PLAY appeals to musicians.
  501.                              I'll explain how the typical 
  502. computer handles the words BEEP, SOUND, and PLAY; but check the 
  503. ``Versions of BASIC'' appendix to find out whether your computer 
  504. handles them differently.
  505.  
  506.                                                  BEEP
  507.                              If you type ___ 
  508. BEEP
  509. the typical computer will beep. Specifically, it will play a note 
  510. whose frequency (``pitch'') is 800 hertz, and it will play the 
  511. note for a quarter of a second.
  512.                              You can say BEEP in the middle of 
  513. your program. For example, you can tell the computer to BEEP if a 
  514. person enters wrong data.
  515.                              Computerized weddings This program 
  516. makes the computer act as a priest and perform a marriage 
  517. ceremony:
  518. 10 INPUT "DO YOU TAKE THIS WOMAN TO BE YOUR LAWFUL WEDDED 
  519. WIFE";A$
  520. 20 IF A$<>"I DO" THEN BEEP: PRINT "TRY AGAIN!": GO TO 10
  521. 30 INPUT "DO YOU TAKE THIS MAN TO BE YOUR LAWFUL WEDDED 
  522. HUSBAND";A$
  523. 40 IF A$<>"I DO" THEN BEEP: PRINT "TRY AGAIN!": GO TO 30
  524. 50 PRINT "I NOW PRONOUNCE YOU HUSBAND AND WIFE."
  525.                              Line 10 makes the computer ask the 
  526. groom, ``DO YOU TAKE THIS WOMAN TO BE YOUR LAWFUL WEDDED WIFE?'' 
  527. If the groom doesn't say ``I DO'', line 20 makes the computer 
  528. beep, say ``TRY AGAIN!'', and repeat the question. Lines 30 and 
  529. 40 do the same thing to the bride. Line 50 congratulates the 
  530. couple for having answered correctly.
  531.  
  532.                                                  SOUND
  533.                              If you type ___ 
  534. SOUND 440,18.2
  535. the typical computer will produce a sound. In that command, the 
  536. 440 is the frequency (``pitch''), measured in hertz (cycles per 
  537. second); so the sound will be a musical note whose pitch is 440 
  538. hertz. (That note happens to be ``the A above middle C'').
  539.                              If you replace the 440 by a higher 
  540. number, the sound will have a higher pitch.
  541.                              When you were a baby, you could 
  542. probably hear up to 20000. As you get older, your hearing gets 
  543. worse, and you can't hear such high notes. Today, the highest 
  544. sound you can hear is probably somewhere around 14000.
  545.                              To find out, give yourself a hearing 
  546. test, by running this program:
  547. 10 INPUT "WHAT PITCH WOULD YOU LIKE ME TO PLAY";P
  548. 20 SOUND P,18.2
  549. 30 GO TO 10
  550.                              When you run that program, begin by 
  551. inputting a low pitch (such as 200). Then input a higher number, 
  552. then an even higher number, until you finally pick a number so 
  553. high you can't hear it. (When trying that test, put your ear 
  554. close to the computer's speaker, which is in the computer's front 
  555. left corner.) When you've picked a number too high for you to 
  556. hear, try a slightly lower number. Keep trying different numbers, 
  557. until you find the highest number you can hear.
  558.                              Have a contest with your friends: 
  559. find out which of your friends can hear best.
  560.                              If you run that program every year, 
  561. you'll see that your hearing gets gradually worse. For example, 
  562. when I was 36 years old, the highest pitch I could hear was about 
  563. 14500, but I can't hear that high anymore. How about you?
  564.                              In those examples, the 18.2 makes 
  565. the computer produce the sound for 1 second. If you want the 
  566. sound to last longer ___ so that it lasts 2 seconds ___ replace 
  567. the 18.2 by 18.2*2. For 10 seconds, say 18.2*10. (That's because 
  568. the computer's metronome beats 18.2 times per second.)
  569.                 PLAY
  570.   If you type ___ 
  571. PLAY "CDG#B-A"
  572. the typical computer will play the note C, then D, then G sharp, 
  573. then B flat, then A.
  574.   Octave The computer can play in seven octaves, numbered from 0 
  575. to 6. Octave 0 consists of very bass notes; octave 6 consists of 
  576. very high-pitched notes. In each octave, the lowest note is a C: 
  577. the notes in an octave are C, C#, D, D#, E, F, F#, G, G#, A, A#, 
  578. and B.
  579.   ``Middle C'' is at the beginning of octave 2. Normally, the 
  580. computer plays in octave 4. To make the computer switch to octave 
  581. 3, type the letter ``O'' followed by a 3, like this:
  582. PLAY "O3"
  583. After giving that command, anything else you PLAY will be in 
  584. octave 3, until you change octaves again.
  585.   Length Besides playing with pitches, you can also play with 
  586. rhythms (``lengths'' of the notes). Normally each note is a 
  587. ``quarter note''. To make the computer switch to eighth notes 
  588. (which are faster), type this:
  589. PLAY "L8"
  590.   Besides using L8 for eighth notes, you can use L16 for 
  591. sixteenth notes (which are even faster), L32 for thirty-second 
  592. notes (which are super-fast), and L64 for sixty-fourth notes 
  593. (which are super-super-fast). For long notes, you can use L2 
  594. (which gives a half note) or L1 (which gives a whole note).
  595.   You can use any length from L1 to L64. You can even use 
  596. in-between lengths, such as L7 or L23 (though such rhythms are 
  597. hard to stamp your foot to).
  598.   Dots If you put a period after a note, the computer will 
  599. multiply the note's length by 1½.
  600.   For example, suppose you say:
  601. PLAY "L8CE.D"
  602. The C will be an 8th note, E will be 1½ times as long as an 8th 
  603. note, and D will be an 8th note. Musicians call that E a dotted 
  604. eighth note.
  605.   If you put two periods after a note (like this: E..), the 
  606. computer will multiply the note's length by 13/4. Musicians say 
  607. the note is double dotted.
  608.   If you put three periods after a note (like this: E...), the 
  609. computer will multiply the note's length by 17/8.
  610.   Pause To make the computer pause (``rest'') for an eighth note, 
  611. put a P8 into the music string.
  612.   Tempo Normally, the computer plays 120 quarter notes per 
  613. minute; but you can change that tempo. To switch to 150 quarter 
  614. notes per minute, say:
  615. PLAY "T150"
  616.   You can switch to any tempo from 32 to 255. The 32 is very 
  617. slow; 255 is very fast. In musical terms, 40=larghissimo, 
  618. 50=largo, 63=larghetto, 65=grave, 68=lento, 71=adagio, 
  619. 76=andantino, 92=andante, 114=moderato, 120=allegretto, 
  620. 144=allegro, 168=vivace, 188=presto, and 208=prestissimo.
  621.   Combine them You can combine all those musical commands into a 
  622. single PLAY statement. For example, to set the tempo to 150, the 
  623. octave to 3, the length to 8 (which means an eighth note), and 
  624. then play C and D, and then change the length to 4 and play E, 
  625. type this:
  626. PLAY "T150O3L8CDL4E"
  627.  
  628.  
  629.              PRINT USING
  630.                                          Suppose you want to add 
  631. $12.47 to $1.03. The correct answer is $13.50. This almost works:
  632. PRINT 12.47+1.03
  633. It makes the computer print:
  634.  13.5
  635. But instead of 13.5, we should try to make the computer print 
  636. 13.50.
  637.                                          This command forces the 
  638. computer to print 13.50:
  639. PRINT USING "##.##"; 12.47+1.03
  640. The ``##.##'' is called the picture or image or format: it says 
  641. to print two characters, then a decimal point, then two digits. 
  642. The computer will print:
  643. 13.50
  644.                                          This command puts that 
  645. answer into a sentence:
  646. PRINT USING "YOU SPENT ##.## AT OUR STORE"; 12.47+1.03
  647. The computer will print:
  648. YOU SPENT 13.50 AT OUR STORE
  649.  
  650.                                                      Rounding
  651.                                          This program makes the 
  652. computer divide 300 by 7 but round the answer to two decimal 
  653. places:
  654. PRINT USING "##.##"; 300/7
  655. When the computer divides 300 by 7, it gets 42.8571, but the 
  656. format rounds the answer to 42.86. The computer will print:
  657. 42.86
  658.  
  659.                                                  Multiple numbers
  660.                                          Every format (such as 
  661. ``###.##'') is a string. You can replace the format by a string 
  662. variable:
  663. 10 A$="###.##"
  664. 20 PRINT USING A$; 247.91
  665. 30 PRINT USING A$; 823
  666. 40 PRINT USING A$; 7
  667. 50 PRINT USING A$; -5
  668. 60 PRINT USING A$; -80.3
  669. The computer will print:
  670. 247.91
  671. 823.00
  672.   7.00
  673.  -5.00
  674. -80.30
  675. When the computer prints that column of numbers, notice that the 
  676. computer prints the decimal points underneath each other so that 
  677. they line up. So to make decimal points line up, say PRINT USING 
  678. instead of just PRINT.
  679.                                          To print those numbers 
  680. across instead of down, say this:
  681. PRINT USING "###.##"; 247.91,823,7,-5,-80.3
  682. It makes the computer print 247.91, then 823.00, etc., like this:
  683. 247.91823.00  7.00 -5.00-80.30
  684. Since the computer prints those numbers so close together, 
  685. they're hard to read. To make the computer insert extra space 
  686. between the numbers, widen the format by putting a fourth ``#'' 
  687. before the decimal point:
  688. PRINT USING "####.##"; 247.91,823,7,-5,-80.3
  689. Then the computer will print:
  690.  247.91 823.00   7.00  -5.00 -80.30
  691.  
  692.   If you say ___ 
  693. PRINT USING "MY ## PALS DRANK ###.# PINTS OF GIN"; 24,983.5
  694. the computer will print:
  695. MY 24 PALS DRANK 983.5 PINTS OF GIN
  696.  
  697.           Oversized numbers
  698.   Suppose you say:
  699. PRINT USING "###.##"; 16238.7
  700.   The computer tries to print 16238.7 by using the format 
  701. ``###.##''. But since that format allows just three digits before 
  702. the decimal point, the format isn't large enough to fit 16238.7. 
  703. So the computer must disobey the format. But the computer also 
  704. prints a percent sign, which means, ``Warning! I am disobeying 
  705. you!'' Altogether, the computer prints:
  706. %16238.70
  707.  
  708.            Final semicolon
  709.   At the end of the PRINT USING statement, you can put a 
  710. semicolon:
  711. 10 PRINT USING "##.##"; 13.5;
  712. 20 PRINT "CREDIT"
  713.   Line 10 makes the computer print 13.50. The semicolon at the 
  714. end of line 10 makes the computer print CREDIT on the same line, 
  715. like this:
  716. 13.50CREDIT
  717.  
  718.           Advanced formats
  719.   Suppose you're running a high-risk business. On Monday, your 
  720. business runs badly: you lose $27,931.60, so your ``profit'' is 
  721. minus $27,931.60. On Tuesday, your business does slightly better 
  722. than break-even: your net profit for the day is $8.95.
  723.   Let's make the computer print the word PROFIT, then the amount 
  724. of your profit (such as -$27,931.60 or $8.95), then the word HA 
  725. (because you're cynical about how your business is going).
  726.   You can do that printing in several ways. Let's explore them. . 
  727. . . 
  728.   If you say ___ 
  729. 10 A$="PROFIT######.##HA"
  730. 20 PRINT USING A$; -27931.6
  731. 30 PRINT USING A$; 8.95
  732. the computer will print:
  733. PROFIT-27931.60HA
  734. PROFIT     8.95HA
  735.   Comma If you change the format to ``PROFIT###,###.##HA'', the 
  736. computer will insert a comma if the number is large:
  737. PROFIT-27,931.60HA
  738. PROFIT      8.95HA
  739.   Plus sign If you change the format to ``PROFIT+#####.##HA'', 
  740. the computer will print a plus sign in front of any positive 
  741. number:
  742. PROFIT-27931.60HA
  743. PROFIT    +8.95HA
  744.   Trailing minus To print a negative number, the computer 
  745. normally prints a minus sign before the number. That's called a 
  746. leading minus. You can make the computer put the minus sign after 
  747. the number instead; that's called a trailing minus. For example, 
  748. if you change the format to ``PROFIT######.##-HA'', the computer 
  749. will print a
  750. minus sign after a negative number (and no minus after a positive 
  751. number), like this:
  752. PROFIT27931.60-HA
  753. PROFIT    8.95 HA
  754.                                          Dollar sign Normally, a 
  755. format begins with ##. If you begin with $$ instead (like this: 
  756. ``PROFIT$$#####.##HA''), the computer will print a dollar sign 
  757. before the digits:
  758. PROFIT-$27931.60HA
  759. PROFIT     $8.95HA
  760.                                          Check protection If you 
  761. begin with ** (like this: ``PROFIT**#####.##HA''), the computer 
  762. will print asterisks before the number:
  763. PROFIT*-27931.60HA
  764. PROFIT******8.95HA
  765.                                          If you begin with **$ 
  766. (like this: ``PROFIT**$#####.##HA''), the computer will print 
  767. asterisks and a dollar sign:
  768. PROFIT*-$27931.60HA
  769. PROFIT******$8.95HA
  770.                                          When you're printing a 
  771. paycheck, use the asterisks to prevent the employee from 
  772. enlarging his salary. Since the asterisks protect the check from 
  773. being altered, they're called check protection.
  774.                                          Combination You can 
  775. combine several techniques into a single format. For example, you 
  776. can combine the comma, the trailing minus, and the **$ (like 
  777. this: ``PROFIT**$##,###.##-HA''), so that the computer will 
  778. print:
  779. PROFIT**$27,931.60-HA
  780. PROFIT*******$8.95 HA
  781.                                          E notation If you change 
  782. the format to ``PROFIT##.#####^^^^HA'', the computer will print 
  783. numbers by using E notation:
  784. PROFIT-2.79316E+04HA
  785. PROFIT 8.95000E+00HA
  786.